package cn.woblog.recyclerviewsample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

public class NewsDetailActivity extends AppCompatActivity {

  public static final String URL = "URL";
  private ImageView iv;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_news_detail);

//    ListView listView = new ListView(this);
//    listView.setOnItemLongClickListener();

    String url = getIntent().getStringExtra(URL);

    iv = (ImageView) findViewById(R.id.iv);

    Glide.with(this).load(url).diskCacheStrategy(DiskCacheStrategy.ALL)
        .into(iv);

//    Glide.with(NewsDetailActivity.this).load(url).diskCacheStrategy(DiskCacheStrategy.ALL)
//        .into(new SimpleTarget<GlideDrawable>() {
//          @Override
//          public void onResourceReady(GlideDrawable resource,
//              GlideAnimation<? super GlideDrawable> glideAnimation) {
//            Log.d("TAG", iv.getWidth() + "," + resource.getIntrinsicWidth());
//            //计算ImageView的高度
//            int imageWidth = resource.getIntrinsicWidth();
//            int imageHeight = resource.getIntrinsicHeight();
//            int imageViewWidth = iv.getWidth();
//
//            double scale = imageWidth * 1.0 / imageViewWidth;
//            LayoutParams layoutParams = iv.getLayoutParams();
//            int h = (int) (imageHeight / scale);
//            layoutParams.height = h;
//            iv.setLayoutParams(layoutParams);
//
//            iv.setImageDrawable(resource);
//          }
//        });
  }


}
